<?php 
	$self = false;
	$IsAuthenticated = false;
	if ($_SESSION[SESSION_AUTHENTICATION_GUID] && $_SESSION[SESSION_AUTHENTICATION_GUID]!="") {
		$self = User::GetUserByUid($_SESSION[SESSION_AUTHENTICATION_GUID]);
		if (!$self || !$self->Initialized) {
			$_SESSION[SESSION_AUTHENTICATION_GUID] = false;
			$self = false;
			$IsAuthenticated = false;
		} else {
			$IsAuthenticated = true;
		}
	} else {
		if (isset($_COOKIE[COOKIE_USERGUID]) && isset($_COOKIE[COOKIE_PASSWORD])) {
			$userGUID = sanitize($_COOKIE[COOKIE_USERGUID]);
			$userPassword = sanitize($_COOKIE[COOKIE_PASSWORD]);
			if ($userGUID && $userPassword) {
				$auth_user = User::Authenticate($userGUID, $userPassword, true);
				if ($auth_user->Initialized) {
					$self = $auth_user;
					$IsAuthenticated = true;
					$_SESSION[SESSION_AUTHENTICATION_GUID] = $auth_user->UID;
				}
			}
		}
	}
	if (isset($_GET["view"]) && $_GET["view"]!="")
	{
		$viewKey = $_GET["view"];
	} else {
		$viewKey = "main";
	}
	$viewKey = strtolower($viewKey);
	$view = array_key_exists($viewKey, $views)? $views[$viewKey] : $views["404"];
	if ($view["requireAuthentication"] && !$IsAuthenticated) {
		$view = $views["login"];
	}
	$viewKey = $view["key"];
?>